package com.atguigu.gmall.juc.juc;

/**
 * @author 陈昆昆
 * @version 1.0
 * @date 2020/5/28 15:04
 */
public class VolatileAuto {
    public static void main(String[] args) {
        Mydata mydata = new Mydata();

        for (int i = 0; i < 20; i++) {
            new Thread(() -> {
                for (int j = 0; j < 1000; j++) {
                    mydata.addplus();
                    mydata.ayomicAdd();
                }
            }, String.valueOf(i)).start();
        }

        while (Thread.activeCount()>2){
            Thread.yield();
        }

        System.out.println(Thread.currentThread().getName()+"---->"+mydata.number);
        System.out.println(Thread.currentThread().getName()+"atomic--->"+mydata.atomicInteger);
    }
}
